function [OUT_Bits] = HF_Interleaving(IN_Bits,Rate,Interleaver_L)

%*--------------------------------------- HF_Interleaving -------------------------------------------%
% 
% [OUT_Bits] = HF_Interleaving(IN_Bits,Rate,Interleaver)
%
% HF block interleaving,and note that the length of input block (IN_Bits) must match 
% with the interleaver size, the output (OUT_Bits) is a matrix of the
% frames, while the input is a vector
%
%
%*------ INTERLEAVER SIZE AS FN OF DATA RATE AND INTERLEAVER LENGTH ------------------%
%
%                                       INTERLEAVER LENGTH IN FRAMES 
%                           
%                       1            3            9        18          36            72      
%DATA RATE         
%
%  3200                 512        1536         4608      9216        18432         36864
%  4800                 768        2304         6912      13824       27648         55296
%  6400                 1024       3072         9216      18432       36864         73728
%  8000                 1280       3840         11520     23040       46080         92160
%  9600                 1536       4608         13824     27648       55296         110592
%
%*-------------------------------------------------------------------------------------%
%
%*------ INCREMENT VALUE AS FN OF DATA RATE AND INTERLEAVER LENGTH --------------------%
%
%                                       INTERLEAVER LENGTH IN FRAMES 
%                           
%                      1           3            9              18         36              72      
%DATA RATE         
%
%  3200                 97         229         805            1393      3281            6985
%  4800                 145        361         1045           2089      5137            10273
%  6400                 189        481         1393           3281      6985            11141
%  8000                 201        601         1741           3481      8561            14441
%  9600                 229        805         2089           5137      10273           17329
%
%*-------------------------------------------------------------------------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%*--------------------------------- INITIALIZATIONS -----------------------------------%
%*-------------------------------------------------------------------------------------%

global Load_Location

%*-------------------------------------------------------------------------------------%
LUT_Interleaver = [512        1536         4608      9216        18432         36864;
                   768        2304         6912      13824       27648         55296;
                   1024       3072         9216      18432       36864         73728;
                   1280       3840         11520     23040       46080         92160;
                   1536       4608         13824     27648       55296         110592];


LUT_Increment = [97         229         805           1393     3281          6985;
                 145        361         1045          2089     5137          10273;
                 189        481         1393          3281     6985          11141;
                 201        601         1741          3481     8561          14441;
                 229        805         2089          5137     10273         17329];
%*-------------------------------------------------------------------------------------%

Data_Rates = [3200 4800 6400 8000 9600];
Interleaver_Lengths = [1 3 9 18 36 72];
Rate_Index = find(Data_Rates==Rate);
Interleaver_Index = find(Interleaver_Lengths==Interleaver_L);

% the following condition to accept the input rate and interleaver size
if (length(IN_Bits) ~= LUT_Interleaver(Rate_Index,Interleaver_Index) )
    disp('Error : the input block size doesnot match with the interleaver size')
    Rate_Index = 0;
    Interleaver_Index = 0;
end
%*-------------------------------------------------------------------------------------%

OUT_Bits(Load_Location) = IN_Bits;
% to put the output as a matrix of the corresponding frames to be suitable
% for the following processes (on the frames)
OUT_Bits = reshape( OUT_Bits,length(IN_Bits)/Interleaver_L,Interleaver_L).';
%*-------------------------------------------------------------------------------------%

